package com.ycfmedical.bed.present;


import android.text.Html;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;

import com.ycfmedical.bed.Constants;
import com.ycfmedical.bed.bean.TextContent;
import com.ycfmedical.bed.local.DataManager;
import com.ycfmedical.bed.local.dao.HisSystemInfoDao;
import com.ycfmedical.bed.local.entity.BillRecords;
import com.ycfmedical.bed.local.entity.HisSystemInfo;
import com.ycfmedical.bed.ui.fragment.CheckBillFragment;

import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.kit.Kits;
import cn.droidlover.xdroidmvp.mvp.XPresent;

/**
 * Created by yf on 2017-04-20.
 */

public class BillCheckPrensenter extends XPresent<CheckBillFragment> {

    public void loadData() {
        List<HisSystemInfo> allHisInfoList = HisSystemInfoDao.getAllHisInfoList();
        List<HisSystemInfo> HisInfoList = new ArrayList<HisSystemInfo>();


        if (!Kits.Empty.check(allHisInfoList))
        {
            for (HisSystemInfo hisSystemInfo : allHisInfoList)
            {
                if (null != DataManager.getInstance().getUser())
                {
                    if (hisSystemInfo.getId() == DataManager.getInstance().getUser().getId())
                    {
                        // setData(hisSystemInfo);
                        // 取出数据
                        // HisInfoList.add(hisSystemInfo);
                        
                        setRecordsData(hisSystemInfo);
                        setResultData(hisSystemInfo);
                    }
                }
            }

        } else {
            // 当前数据库中不存在数据
        }
    }

    private BillRecords setData(String c1,String c2,String c3,String c4 ) {
        BillRecords billRecords=new BillRecords();
        billRecords.setExcelC1(c1);
        billRecords.setExcelC2(c2);
        billRecords.setExcelC3(c3);
        billRecords.setExcelC4(c4);
        return billRecords;
    }

    private void setResultData(HisSystemInfo hisSystemInfo) {
 //     Spanned s= Html.fromHtml("<font color=\'#858585\'>购买前如有任何疑问，欢迎使用：</font><font color=\'#f02387\'><U>购物咨询</U></font>");
        float yujiaokuan = 5000;
        float yiyongkuan = hisSystemInfo.getCure() + hisSystemInfo.getHospital() + hisSystemInfo.getInspection()
                + hisSystemInfo.getMedicine() + hisSystemInfo.getNurse();
        float zifujine = yiyongkuan - yiyongkuan * hisSystemInfo.getHealthinsurance();
        float scale = hisSystemInfo.getHealthinsurance();

        float bujiaojine = 0;
        if (yujiaokuan - zifujine < 0) {
            bujiaojine = zifujine-yujiaokuan;
        }

        List<BillRecords> billList = new ArrayList<BillRecords>();

        billList.add(setData("预交款","已用款","自付金额","补交金额"));

        billList.add(setData(yujiaokuan+"￥",yiyongkuan+"￥",zifujine+"￥",bujiaojine+"￥"));

        getV().showResultsData(billList);
    }

    private void setRecordsData(HisSystemInfo hisSystemInfo) {

        List<BillRecords> billList = new ArrayList<BillRecords>();
        float scale = hisSystemInfo.getHealthinsurance();
        billList.add(setData("项目", "费用", "医保", "备注"));
        billList.add(setData("住院费",
                hisSystemInfo.getHospital() + "", hisSystemInfo.getHospital() + "*" + scale * 100 + "%", "医疗证号：111000"));
        billList.add(setData("检查费",
                hisSystemInfo.getInspection() + "", hisSystemInfo.getInspection() + "*" + scale * 100 + "%", "医保类型：职工医保"));
        billList.add(setData("护理费",
                hisSystemInfo.getNurse() + "", hisSystemInfo.getNurse() + "*" + scale * 100 + "%", "报销类型：住院报销"));
        billList.add(setData("治疗费",
                hisSystemInfo.getCure() + "", hisSystemInfo.getCure() + "*" + scale * 100 + "%", "起付金额：500"));
        billList.add(setData("用药费",
                hisSystemInfo.getMedicine() + "", hisSystemInfo.getMedicine() + "*" + scale * 100 + "%", "报销比例" + scale * 100 + "%"));


      getV().showRecordsData(billList);

    }



}
